Skip to content

feat(worker): withhold stale PR review output when the head moves mid-session (#8) - #42

Merged
BunsDev merged 1 commit into
mainfrom
feat/issue-8-stale-ref-gate
Jul 7, 2026
Merged

feat(worker): withhold stale PR review output when the head moves mid-session (#8)#42
BunsDev merged 1 commit into
mainfrom
feat/issue-8-stale-ref-gate

Conversation

@BunsDev

@BunsDev BunsDev commented Jul 7, 2026

Copy link
Copy Markdown
Member

Closes #8 — the last remaining gap: pre-publish stale-ref revalidation.

What was already true on main

The target-resolution work that landed with #10 (resolve_targets) had already satisfied most of #8's acceptance criteria:

  • No Check Run path uses a literal "HEAD" — issue tasks resolve the default-branch tip SHA, PR tasks resolve the PR's own head/base refs, all live from the GitHub API
  • PR tasks attach checks to the PR head SHA
  • Queued reviews are superseded at dequeue when a newer event registers (the Implement PR, push, and commit review triggers #10 supersession registry)
  • Fixtures cover issue / PR review comment / PR synchronize / push parsing (crates/webhook/tests/parse_fixtures.rs)

Push/commit execution remains a contract-v3 lane (documented planned lane, tracked under #10's notes) — parsed and typed today.

What this PR adds

The one window still open: a PR head that moves while the review session runs. The supersession registry only guards dequeue; a review already in flight would still publish findings computed against a commit the PR no longer points at.

Now, after the session and before any publication, ReviewPullRequest tasks re-fetch the PR refs and compare against the reviewed head:

  • head unchanged → normal publication path, unchanged behavior
  • head moved → findings withheld: Check Run completes neutral / "Stale" naming both SHAs, the marker-backed status comment flips to Status: superseded with retry guidance, and the Cave task list gets a new honest terminal state superseded (additive TaskListStatus variant, wired through the status command's labels)

Verification

  • New wiremock proof review_of_moved_head_is_published_as_superseded: first PR fetch returns sha-reviewed, the pre-publish re-fetch returns sha-moved; asserts neutral/Stale terminal check PATCH (never success), Status: superseded on the comment surface, the finding text withheld, and TaskListStatus::Superseded in the store
  • cargo check --all-targets, cargo clippy --all-targets -- -D warnings, cargo test --all (135 passed), python gates — all green
  • README Check Run status row updated from Partial → Implemented

…-session (#8)

Re-fetch the PR refs after the session and before publication. If the head
advanced while the review ran, complete the Check Run as neutral/Stale,
surface 'Status: superseded' on the marker-backed status comment, and mark
the task superseded in the Cave task list — the findings are never presented
as if they covered the current head. The newer push's own event (or a
maintainer retry) reviews the fresh head.

This closes the last gap in issue #8: check runs already attach to resolved
immutable SHAs (no 'HEAD' placeholders since the #10 target-resolution work),
and queued reviews are already superseded at dequeue; this adds the
mid-session window.

Signed-off-by: Val Alexander <bunsthedev@gmail.com>
Copilot AI review requested due to automatic review settings July 7, 2026 03:11
@BunsDev
BunsDev merged commit 30b84d6 into main Jul 7, 2026
2 checks passed
@BunsDev
BunsDev deleted the feat/issue-8-stale-ref-gate branch July 7, 2026 03:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements a pre-publish staleness gate for ReviewPullRequest tasks so the worker withholds review findings if the PR head SHA changes while a session is running, preventing publication of output against a commit the PR no longer targets.

Changes:

  • Re-fetch PR refs immediately before publication and, if the head SHA changed, treat the run as superseded and complete the Check Run as neutral with a “Stale” output.
  • Add an additive TaskListStatus::Superseded state and wire it into the status command labeling.
  • Add a Wiremock-backed integration test covering the “head moved mid-session” withholding behavior; update README capability status.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
README.md Updates capability status to reflect implemented stale-ref revalidation behavior for Check Runs.
crates/worker/src/lib.rs Adds the stale-ref pre-publish revalidation gate, superseded publication path, and a Wiremock test ensuring findings are withheld when the PR head moves.
crates/webhook/src/routes.rs Adds superseded labeling for the status command output.
crates/github/src/tasks.rs Introduces TaskListStatus::Superseded and a mark_superseded helper on TaskStore.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve Check Run head SHA and target ref correctly

2 participants